#include "inner_msg.h"

Inner_Msg::Inner_Msg()
{
 this->now = 0;
 this->nowClient =0;
}
void Inner_Msg::AddNode_Relay()
{
    InfoChain.append("Relay");
}
void Inner_Msg::AddNode_SQL()
{
    InfoChain.append("SQL");
}
void Inner_Msg::AddNode(Client_Server* Node)
{
    InfoChain.append("CLIENT");
    ClientAddress.append(Node);
}
void Inner_Msg::AddNodes(QVector<Client_Server*> &Nodelist)
{
    for(int i = 0;i<Nodelist.size();i++)
        InfoChain.append("CLIENTS");
    ClientAddress = ClientAddress + Nodelist;
}
void Inner_Msg::SendToRelay()
{
    this->now ++;
    Msg_Relay::gethand()->Add_Message(this);
}
void Inner_Msg::GetClientByData()
{
    QVector<Client_Server*>templist;
    QJsonDocument QJson;
    QJson.fromJson(Data["uidlist"].toUtf8());

    for(int i = 0;i <QJson.object()["uidlist"].toArray().size();i++)
    {
        for(int j = 0;j<Server_Main::Online_Usr.size();j++)
        {
            if(Server_Main::Online_Usr[j]->uid == QJson.object()["uidlist"].toArray()[i].toString())
            {
                templist.push_back(Server_Main::Online_Usr[j]);
            }
        }
    }
    this->AddNodes(templist);
}
void Inner_Msg::PostSQL(Client_Server* client,QString Type,QString Operate)
{
    this->Msg_Type = Type;
    ClientAddress.clear();
    InfoChain.clear();
    Data.clear();

    AddNode(client);
    AddNode_Relay();
    AddNode_SQL();
    AddNode_Relay();
    AddNode(client);

    this->Msg_Type = Type;

    this->Data.insert("SQL_OPERATE",Operate);
}

